package org.itboys.core.controller.web.wallet;

import org.itboys.core.entity.mysql.wallet.record.SundayWalletRecord;
import org.itboys.core.service.mysql.front.SundayFrontWalletRecordService;
import org.itboys.core.service.mysql.web.SundayWalletService;
import org.itboys.core.util.MybatisParamUtil;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author：贾琦磊
 * @Date：2018/12/3
 * @Description：web端提现审核
 */
@Controller
@RequestMapping("/sunday/web/wallet/record")
public class SundayWalletRecordController extends BaseController {
    @Autowired
    private SundayWalletService walletService;
    @Autowired
    private SundayFrontWalletRecordService walletRecordService;

    /**
     * 用户提现申请
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/index")
    public String withdraw_index(HttpServletRequest request, HttpServletResponse response,Model model
            , @RequestParam(value = "walletId", required = false) Long walletId
    ) {
        model.addAttribute("walletId",walletId);
        return "/sunday/record/index";
    }



    @RequestMapping("/select")
    public void select(HttpServletRequest request,
                       HttpServletResponse response
            , @RequestParam(value = "status", required = false) Integer status
            , @RequestParam(value = "type", required = false) List<Integer> types
            , @RequestParam(value = "walletId", required = false) Long walletId
    ) {
        MybatisParamUtil paramUtil = new MybatisParamUtil(request);
        PageResult<SundayWalletRecord> result = walletService.selectPage(paramUtil, status,types,walletId);
        JsonPageUtils.renderJsonPage(result.getTotal(), result.getData(), response);
    }

    @RequestMapping("/save")
    public void updateVouch(HttpServletRequest request,
                             HttpServletResponse response,
                             @RequestParam(value = "id") Long id,
                             @RequestParam(value = "status",required = false) Integer status,
                             @RequestParam(value = "vouch",required = false) MultipartFile vouch
    ) {
        SundayWalletRecord record = new SundayWalletRecord();
        record.setId(id);
        record.setStatus(status);
        walletService.save(record,vouch);
        ResponseMessage.success();
    }

    @RequestMapping("/update")
    public void updateStatus(HttpServletRequest request,
                             HttpServletResponse response,
                             @RequestParam(value = "id") Long id,
                             @RequestParam(value = "status",required = false) Integer status
    ) {
        walletRecordService.updateStatus(id,status);
        ResponseMessage.success();
    }
}
